package com.ellfors.common.utils

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import java.lang.reflect.Type

/**
 * @date: 2024/06/14
 * @author: ly
 * @Description: ARouter传递对象所需的解析类
 */
@Route(path = "/ellfors/json")
class ARouterJsonService : SerializationService {
    override fun init(context: Context?) {

    }

    @Deprecated("Deprecated in Java", ReplaceWith("JsonUtil.json2Obj(input, clazz)!!"))
    override fun <T : Any?> json2Object(input: String?, clazz: Class<T>?): T {
        return JsonUtil.json2Obj(
            input, clazz
        ) ?: throw RuntimeException("ARouter json2Object error")
    }

    override fun object2Json(instance: Any?): String {
        return JsonUtil.obj2Json(instance)
    }

    override fun <T : Any?> parseObject(input: String?, clazz: Type?): T {
        return JsonUtil.json2Obj(
            input, clazz
        ) ?: throw RuntimeException("ARouter parseObject error")
    }
}